package com.cskaoyan.exception;

import com.cskaoyan.model.vo.extend.BaseRespVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author：Chunk
 * @Description:
 * @Date Created in 21:10 2021/4/11
 */
@ControllerAdvice
public class ExceptionController {
    @ExceptionHandler(GoodsIdNonexistentException.class)
    @ResponseBody
    public BaseRespVo goodsIdNonexistent(){
        return BaseRespVo.error("参数值不对");
    }

    @ExceptionHandler(CouponReceiveException.class)
    @ResponseBody
    public BaseRespVo couponReceiveException(CouponReceiveException ex){
        String errmsg = ex.getErrmsg();
        Integer errno = ex.getErrno();
        return BaseRespVo.error(errno, errmsg);
    }

    @ExceptionHandler(CouponEmptyException.class)
    @ResponseBody
    public BaseRespVo couponEmptyException(){
        return BaseRespVo.error(740,"手慢了，该优惠券被领完了");
    }
}
